package com.android.videotest.video;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.FrameLayout;

import com.android.videotest.R;

import java.io.Serializable;

public class VideoDetailActivity extends AppCompatActivity {

    private VideoWrapper mVideoWrapper;

    public static void start(Context context) {
        Intent starter = new Intent(context, VideoDetailActivity.class);
        context.startActivity(starter);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_detail);
        FrameLayout contentPanel = findViewById(R.id.contentPanel);
        mVideoWrapper = VideoWrapper.getInstance(getApplicationContext());
        mVideoWrapper.setActivity(this);
        ViewGroup parent = (ViewGroup) mVideoWrapper.getParent();
        if (parent != null) {
            parent.removeView(mVideoWrapper);
        }
        contentPanel.addView(mVideoWrapper, -1, -2);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (mVideoWrapper != null) {
            mVideoWrapper.start();
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (mVideoWrapper != null) {
            mVideoWrapper.pause();
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
//        if (mVideoWrapper != null) {
//            mVideoWrapper.stop();
//        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mVideoWrapper != null) {
            mVideoWrapper.onDestroy();
        }
    }
}
